#include <cstdio>
#include <cstring>
#include <queue>

typedef long long ll;
const int N = 100005;
int x, y, z;
int e_cnt, heads[N];
ll h, dis[N];
bool vis[N];

std::queue<int> q;

struct Edge {
  int v, nxt, w;
} e[N << 1];

inline void add(int u, int v, int w) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt, e[e_cnt].w = w;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("CongruentShortestPath.in", "r", stdin);
  freopen("CongruentShortestPath.out", "w", stdout);
#endif
#endif

  scanf("%lld", &h);
  scanf("%d%d%d", &x, &y, &z);
  if (x == 1 || y == 1 || z == 1) return printf("%lld", h), 0;
  for (int i = 0; i < x; ++i) {
    add(i, (i + y) % x, y);
    add(i, (i + z) % x, z);
  }
  memset(dis, 0x3f, sizeof(dis));
  q.push(1);
  vis[1] = true;
  dis[1] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = false;
    for (int i = heads[u], v; i; i = e[i].nxt) {
      if (dis[v = e[i].v] > dis[u] + e[i].w) {
        dis[v] = dis[u] + e[i].w;
        if (!vis[v]) {
          q.push(v);
          vis[v] = true;
        }
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i < x; ++i) {
    if (h >= dis[i]) ans += (h - dis[i]) / x + 1ll;
  }
  printf("%lld", ans);
  return 0;
}